package xyz.xtt.admin.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import xyz.xtt.admin.constants.ExchangeCache;
import xyz.xtt.admin.entity.TblCollection;
import xyz.xtt.admin.mapper.CollectionMapper;
import xyz.xtt.admin.service.ICollectionService;
import xyz.xtt.common.starter.cache.CacheManager;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-11-21
 */
@Service
public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, TblCollection> implements ICollectionService {

	@Autowired
	private CollectionMapper collectionMapper;

	@Autowired
	private CacheManager cacheManager;

	@Override
	public Page<TblCollection> getList(Integer current, Integer pageSize) {
		return collectionMapper.getList(new Page<>(current, pageSize));
	}

	@Override
	public boolean setTop(Long id, boolean topStatus) {
		Long topTime = topStatus ? System.currentTimeMillis() : 0;
		boolean b = collectionMapper.setTop(id, topTime);
		if (b) {
			cacheManager.delete(ExchangeCache.HOME_TOP);
		}
		return b;
	}
}
